package string;

public class Work {
    public static void main(String[] args) {
        //1）length();获取字符串的长度(字符个数)
        /*
        String str = "我爱Java";
        int len = str.length();
        System.out.println(len);
         */
        /*
        String str = "我爱java";
        int len = str.length();
        System.out.println(len);

         */

        //2)trim()：去除当前字符串两边的空白字符
        /*
        String str = "      我爱，java    ";
        str = str.trim();
        System.out.println(str);
        */
        /*
        String str = "      我爱java     ";
        str = str.trim();
        System.out.println(str);
         */

        //3）toUpperCase()/toLowerCase()：将当前字符串中的英文部分给转换为全大写/全小写
        /*
        String str = "我爱java!";
        String upper = str.toUpperCase();
        System.out.println(upper);
        String lower = str.toLowerCase();
        System.out.println(lower);
         */
        /*
        String str = "我爱java!";
        String upper = str.toUpperCase();
        System.out.println(upper);
        String lower = str.toLowerCase();
        System.out.println(lower);
         */

        //4)startsWith()/endsWith()：判断当前字符串是否是以给定的定符串开始/结束
        /*
        String str = "我爱java";
        boolean starts = str.startsWith("我");
        System.out.println(starts);
        boolean ends = str.endsWith(".jpg");
        System.out.println(ends);
         */
        /*
        String str = "我爱java!";
        boolean starts = str.startsWith("我爱");
        System.out.println(starts);
        boolean ends = str.endsWith(".a");
        System.out.println(ends);
         */

        //5)charAt()：返回当前字符串指定位置上的字符----根据位置找字符
        /*
        String str = "abcdefg";
        char a  =str.charAt(4);
        System.out.println(a);
         */
        /*
        String str = "asdqwerty";
        char a = str.charAt(5);
        System.out.println(a);
         */

        //6)indexOf()/lastIndexOf()：检索给定字符串在当前字符串中第一次/最后一次出现的位置----根据字符串找位置
        /*
        String str = "thinking in java";
        int index = str.indexOf("in");
        System.out.println(index);
        index = str.indexOf("in",3);
        System.out.println(index);
        index = str.indexOf("abc");
        System.out.println(index);
        index = str.lastIndexOf("in");
        System.out.println(index);
         */
        /*
        String str = "thinking in java";
        int index = str.indexOf("in");
        System.out.println(index);
        index = str.indexOf("in",3);
        System.out.println(index);
        index = str.indexOf("abc");
        System.out.println(index);
        index = str.lastIndexOf("in");
        System.out.println(index);
         */

        //7substring()：截取当前字符串中指定范围的字符串(含头不含尾)
        /*
        String str = "www.tedu.com";
        int start = str.indexOf(".")+1;
        int end = str.lastIndexOf(".");
        String name = str.substring(start,end);
        System.out.println(name);

         */
        /*
        String str = "www.tedu.com";
        int start = str.indexOf(".")+1;
        int end = str.indexOf(".",start);
        String name = str.substring(start,end);
        System.out.println(name);
         */

        //8静态方法valueOf()：将其它数据类型转换为String
        /*
        int a = 123;
        String s1 = String.valueOf(a);
        System.out.println(s1);

        double b = 123.456;
        String s2 = String.valueOf(b);
        System.out.println(s2);

        String s3 = b+"";
        System.out.println(s3);
         */
        /*
        int a = 123;
        String s1 = String.valueOf(a);
        System.out.println(s1);

        double b = 123.456;
        String s2 = String.valueOf(b);
        System.out.println(s2);

        String s3 = b+"";
        System.out.println(s3);
         */


        //StringBuilder的四种方法：
        String str = "好好学习java";
        StringBuilder builder = new StringBuilder(str);
        //1)append()：追加内容---------------------增
        /*
        builder.append(",为了找个好工作");
        System.out.println(builder);
         */
        builder.append(",为了找个好工作");
        System.out.println(builder);

        //2)replace():替换部分内容(含头不含尾)
        /*
        builder.replace(9,16,"为了改变世界");
        System.out.println(builder);
         */
        builder.replace(9,16,"为了改变世界");
        System.out.println(builder);

        //3)delete():删除部分内容(含头不含尾)
        /*
        builder.delete(0,8);
        System.out.println(builder);
         */
        builder.delete(0,8);
        System.out.println(builder);

        //4)insert():插入内容
        /*
        builder.insert(0,"活着");
        System.out.println(builder);
         */
        builder.insert(0,"活着");
        System.out.println(builder);





    }
}
